package ganga.custodian;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * Обработчик события загрузки ОС
 * Запускает сервис CustodianService.
 * @see http://www.androidenea.com/2009/09/starting-android-service-after-boot.html
 * http://code.google.com/p/android-bluetooth-on-motion/source/browse/trunk/BluetoothOnMotion/src/com/elsewhat/android/onmotion/BootReceiver.java
 * @author Apocrypha
 *
 */
public class OnBootReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {

		if (!"android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) 
			throw new RuntimeException("Unexpected action " + intent.getAction()+" in intent for OnBootReceiver.");
		
		// TODO: Прочитать сохранённую настройку автозапуска
		context.startService(new Intent(context, LoggingService.class));
		Helper.log("Custodian service started while device boot.");
	
	}

}